﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using NHibernate;
using NHibernate.Criterion;

using ProjectBase.Core;
using ProjectBase.Data;
using ProjectBase.Data.NH;

using $prjsn$.Common.Data.Services;
using $prjsn$.Entity.Services;

namespace $safeprojectname$.Services
{
    public class UserDao : BaseDao<User, int, UserFilter>, IUserDao
    {
        #region Find
        public override IEnumerable<User> Find(UserFilter filter)
        {
            Criteria.Append(Apply(filter));

            return GetListByCriteria(filter);
        }

        protected override IList<ICriterion> Apply(UserFilter filter)
        {
            var restrictions = base.Apply(filter);

            restrictions.AddCompare(filter, f => f.IdExact); // Searches for exact ID
            restrictions.AddIn(filter, f => f.IDColl);

            restrictions.AddEqual(filter, f => f.LoginExact); // Searches for exact match

            restrictions.AddLike(filter, f => f.Login);
            restrictions.AddLike(filter, f => f.FirstName);
            restrictions.AddLike(filter, f => f.LastName);

            return restrictions;
        }


        #endregion Find

        #region IUserDao Members

        public virtual IEnumerable<User> GetAll()
        {
            var list = Session.CreateCriteria<User>().List<User>();
            return list;
        }
        #endregion

    }
}